package _interview150;

import _object.ListNode;

/**
 * 92. 反转链表 II
 */
public class No92 {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode dummy = new ListNode(-1, head), p0 = dummy;
        for (int i = 1; i < left; i++) {
            p0 = p0.next;
        }
        ListNode pre = null, cur = p0.next, nex;
        for (int i = left; i <= right; i++) {
            nex = cur.next;
            cur.next = pre;
            pre = cur;
            cur = nex;
        }
        p0.next.next = cur;
        p0.next = pre;
        return dummy.next;
    }
}
